From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Thu, 24 Oct 2024 19:12:30 +0000 (-0600) Subject: restore lowranceusr truncation in bytes (#1358) X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~12^2^2~32 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=38e038e8a80b1c9c89e6265ca85b1f11a31539b0;p=gpsbabel.git restore lowranceusr truncation in bytes (#1358) as opposed to QChars. --- diff --git a/lowranceusr.cc b/lowranceusr.cc index 00586f460..25248d49a 100644 --- a/lowranceusr.cc +++ b/lowranceusr.cc @@ -234,6 +234,7 @@ LowranceusrFormat::lowranceusr4_writestr(const QString& buf, gbfile* file, int b QByteArray qba; if (bytes_per_char == 1) { qba = buf.toUtf8(); + qba.truncate(MAXUSRSTRINGSIZE); } else { QScopedPointer encoder(utf16le_codec->makeEncoder(QTextCodec::IgnoreHeader)); qba = encoder->fromUnicode(buf); @@ -1882,16 +1883,8 @@ LowranceusrFormat::write() gbfputint32(DataStreamVersion, file_out); /* file title */ - if (int len = strlen(opt_title); len == 0) { - buf = QString("GPSBabel generated USR data file"); - } else { - if (len > MAXUSRSTRINGSIZE) { - QString title = opt_title.get(); - title.truncate(MAXUSRSTRINGSIZE); - opt_title.set(title); // truncate it before copy - } - buf = opt_title; - } + buf = opt_title.isEmpty()? + QStringLiteral("GPSBabel generated USR data file") : opt_title.get(); if (global_opts.debug_level >= 1) { printf(MYNAME " data_write: Title = '%s'\n", qPrintable(buf)); } @@ -1914,16 +1907,8 @@ LowranceusrFormat::write() gbfputint32(opt_serialnum_i, file_out); /* content description */ - if (int len = strlen(opt_content_descr); len == 0) { - buf = QString("Waypoints, routes, and trails"); - } else { - if (len > MAXUSRSTRINGSIZE) { - QString content_descr = opt_content_descr.get(); - content_descr.truncate(MAXUSRSTRINGSIZE); - opt_content_descr.set(content_descr); // truncate it before copy - } - buf = opt_content_descr; - } + buf = opt_content_descr.isEmpty()? + QStringLiteral("Waypoints, routes, and trails") : opt_content_descr.get(); if (global_opts.debug_level >= 1) { printf(MYNAME " data_write: Description = '%s'\n", qPrintable(buf)); }